
package com.hzh.test01.jackson.JackSonTest;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;


public class JackSonTest {
    public static void main(String[] args) {
        String jsonString = "{\"name\":\"John Doe\",\"age\":30}";

        // 创建ObjectMapper实例
        ObjectMapper objectMapper = new ObjectMapper();

        // 解析JSON字符串为User对象
        User user = null;
        try {
            user = objectMapper.readValue(jsonString, User.class);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }

        // 输出User对象的信息
        System.out.println(user);
    }
}
@Data
class User{
    String name;
    int age;
}
